﻿// IODlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "IODlg.h"
#include "afxdialogex.h"

// CIODlg 对话框

IMPLEMENT_DYNAMIC(CIODlg, CDialogEx)

CIODlg::CIODlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_IO, pParent)
{

}

CIODlg::~CIODlg()
{
}

void CIODlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB_IO, m_tabIO);
}


BEGIN_MESSAGE_MAP(CIODlg, CDialogEx)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_IO, &CIODlg::OnTcnSelchangeTabIo)
END_MESSAGE_MAP()


// CIODlg 消息处理程序


BOOL CIODlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_tabIO.InsertItem(0, L"输入_In");
	m_tabIO.InsertItem(1, L"输出_Out");

	//关联对话框,并且将IDC_TABTEST控件设为父窗口
	m_cControlDlg0.Create(IDD_DIALOG_IO_INPUT, GetDlgItem(IDC_TAB_IO));
	m_cControlDlg1.Create(IDD_DIALOG_IO_OUTPUT, GetDlgItem(IDC_TAB_IO));

	//获得IDC_TABTEST客户区大小
	CRect rs;
	m_tabIO.GetClientRect(&rs);
	//调整子对话框在父窗口中的位置
	rs.top += 25;
	//rs.bottom -= 60;
	rs.left += 1;
	rs.right -= 2;

	//设置子对话框尺寸并移动到指定位置
	m_cControlDlg0.MoveWindow(&rs);
	m_cControlDlg1.MoveWindow(&rs);
	//分别设置隐藏和显示
	m_cControlDlg0.ShowWindow(true);
	m_cControlDlg1.ShowWindow(false);
	//设置默认的选项卡
	m_tabIO.SetCurSel(0);

	return TRUE;  
}


void CIODlg::OnCancel()
{
	m_cControlDlg0.ShowWindow(false);
	m_cControlDlg1.ShowWindow(false);

	CDialogEx::OnCancel();
}


void CIODlg::OnTcnSelchangeTabIo(NMHDR *pNMHDR, LRESULT *pResult)
{
	int CurSel = m_tabIO.GetCurSel();
	switch (CurSel)
	{
	case 0:
		m_cControlDlg0.ShowWindow(true);
		m_cControlDlg1.ShowWindow(false);
		break;
	case 1:
		m_cControlDlg0.ShowWindow(false);
		m_cControlDlg1.ShowWindow(true);
		break;
	}
	*pResult = 0;
}
